| Nicolás Peña Moreno | cf8e881 | 2019-04-01 17:12:02 | [diff] [blame] | 1 | <!DOCTYPE HTML> |
| 2 | <meta charset=utf-8> |
| 3 | <title>Element Timing: observe a rectangular image</title> |
| 4 | <body> |
| 5 | <style> |
| 6 | body { |
| 7 | margin: 20px; |
| 8 | } |
| 9 | </style> |
| 10 | <script src="/resources/testharness.js"></script> |
| 11 | <script src="/resources/testharnessreport.js"></script> |
| 12 | <script src="resources/element-timing-helpers.js"></script> |
| 13 | <script> |
| 14 | let beforeRender; |
| Nicolás Peña Moreno | 66bb6b4 | 2019-05-01 17:40:58 | [diff] [blame] | 15 | let img; |
| Nicolás Peña Moreno | cf8e881 | 2019-04-01 17:12:02 | [diff] [blame] | 16 | async_test(function (t) { |
| 17 | const observer = new PerformanceObserver( |
| 18 | t.step_func_done(function(entryList) { |
| 19 | assert_equals(entryList.getEntries().length, 1); |
| 20 | const entry = entryList.getEntries()[0]; |
| 21 | const index = window.location.href.lastIndexOf('/'); |
| 22 | // Subtracting 14 to remove 'element-timing'. |
| 23 | const pathname = window.location.href.substring(0, index - 14) + |
| 24 | 'images/black-rectangle.png'; |
| Nicolás Peña Moreno | 66bb6b4 | 2019-05-01 17:40:58 | [diff] [blame] | 25 | checkElement(entry, pathname, 'my_image', 'rectangle', beforeRender, img); |
| Nicolás Peña Moreno | cf8e881 | 2019-04-01 17:12:02 | [diff] [blame] | 26 | // Assume viewport has size at least 100, so the element is fully visible. |
| 27 | checkRect(entry, [20, 120, 20, 70]); |
| 28 | checkNaturalSize(entry, 100, 50); |
| 29 | }) |
| 30 | ); |
| 31 | observer.observe({entryTypes: ['element']}); |
| 32 | // We add the image during onload to be sure that the observer is registered |
| 33 | // in time for it to observe the element timing. |
| 34 | window.onload = () => { |
| 35 | // Add image of width equal to 100 and height equal to 50. |
| Nicolás Peña Moreno | 66bb6b4 | 2019-05-01 17:40:58 | [diff] [blame] | 36 | img = document.createElement('img'); |
| Nicolás Peña Moreno | cf8e881 | 2019-04-01 17:12:02 | [diff] [blame] | 37 | img.src = '/images/black-rectangle.png'; |
| Nicolás Peña Moreno | 15d2855 | 2019-04-01 19:03:08 | [diff] [blame] | 38 | img.id = 'rectangle'; |
| Nicolás Peña Moreno | cf8e881 | 2019-04-01 17:12:02 | [diff] [blame] | 39 | img.setAttribute('elementtiming', 'my_image'); |
| 40 | document.body.appendChild(img); |
| 41 | beforeRender = performance.now(); |
| 42 | }; |
| 43 | }, 'Element with rectangular image has correct rect and instrinsic size.'); |
| 44 | </script> |
| 45 | </body> |